package org.example.config;

import org.apache.commons.io.IOUtils;
import org.example.utils.GlobalUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Configuration {

    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration();
        configuration.readProperties("D:\\yunqiongkeji\\selenium_image\\file\\application.properties");
    }

    public ApplicationProperties readProperties(String confPath) throws Exception {
        Properties properties = new Properties();
        InputStream inputStream = null;

        try {
            inputStream = new FileInputStream(confPath);
            properties.load(inputStream);

            String userDataPath = properties.getProperty("userDataPath");
            String offsetX = properties.getProperty("offsetX");
            String offsetY = properties.getProperty("offsetY");
            String ocrType = properties.getProperty("ocrType");
            String saveImgPath = properties.getProperty("saveImgPath");
            String saveLogPath = properties.getProperty("saveLogPath");
            String ocrPath = properties.getProperty("ocrPath");
            String ocrDataPath = properties.getProperty("ocrDataPath");
            String executeArr = properties.getProperty("executeArr");

            ApplicationProperties applicationProperties = new ApplicationProperties();
            applicationProperties.setUserDataPath(userDataPath);
            applicationProperties.setOffsetX(offsetX);
            applicationProperties.setOffsetY(offsetY);
            applicationProperties.setOcrType(ocrType);
            applicationProperties.setSaveImgPath(saveImgPath);
            applicationProperties.setSaveLogPath(saveLogPath);
            applicationProperties.setOcrPath(ocrPath);
            applicationProperties.setOcrDataPath(ocrDataPath);
            applicationProperties.setExecuteArr(executeArr);
            GlobalUtils.logi("get global config: " + applicationProperties);
            return applicationProperties;
        } catch (IOException e) {
            throw new IOException(e);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }
}
